<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic|LiSu:300,300italic,400,400italic,700,700italic|youyuan:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/blog/lib/pace/pace-theme-bounce.min.css">
  <script src="/blog/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zchao666.gitee.io","root":"/blog/","scheme":"Gemini","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="AspectJ是基于java语言实现的AOP框架。使用AspectJ实现Spring AOP有两种方式：基于XML配置开发AspectJ和基于注解开发AspectJ。 基于XML配置开发AspectJ基于XML配置是指 通过XML配置文件定义切面、切入点及通知，所有的定义必须在&lt; aop:config&gt;元素内完成。">
<meta property="og:type" content="article">
<meta property="og:title" content="基于XML配置以及基于注解开发AspectJ实现AOP">
<meta property="og:url" content="https://zchao666.gitee.io/blog/2020/02/26/%E5%9F%BA%E4%BA%8EXML%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91AspectJ%E5%AE%9E%E7%8E%B0AOP/index.html">
<meta property="og:site_name" content="小郭的博客">
<meta property="og:description" content="AspectJ是基于java语言实现的AOP框架。使用AspectJ实现Spring AOP有两种方式：基于XML配置开发AspectJ和基于注解开发AspectJ。 基于XML配置开发AspectJ基于XML配置是指 通过XML配置文件定义切面、切入点及通知，所有的定义必须在&lt; aop:config&gt;元素内完成。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200226131204671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200226135903941.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2020-02-26T07:54:12.000Z">
<meta property="article:modified_time" content="2020-03-05T18:20:15.278Z">
<meta property="article:author" content="小郭">
<meta property="article:tag" content="Spring">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="AOP">
<meta property="article:tag" content="AspectJ">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200226131204671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">

<link rel="canonical" href="https://zchao666.gitee.io/blog/2020/02/26/%E5%9F%BA%E4%BA%8EXML%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91AspectJ%E5%AE%9E%E7%8E%B0AOP/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>基于XML配置以及基于注解开发AspectJ实现AOP | 小郭的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  
  
		<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
		<script>
		/* 社会主体核心价值观效果 */
		var a_idx = 0;
		jQuery(document).ready(function ($) {
		  $("body").click(function (e) {
			var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善");
			var $i = $("<span/>").text(a[a_idx]);
			a_idx = (a_idx + 1) % a.length;
			var x = e.pageX,
			  y = e.pageY;
			$i.css({
			  "z-index": 100000000,
			  "top": y - 20,
			  "left": x,
			  "position": "absolute",
			  "font-family": "LiSu",
			  "font-weight": "bold",
			  "color": "#ff6651"
			});
			$("body").append($i);
			$i.animate({
			  "top": y - 180,
			  "opacity": 0
			}, 1500, function () {
			  $i.remove();
			});
		  });
		});
	</script>
  

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小郭的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-留言">

    <a href="/blog/comments/" rel="section"><i class="fa fa-fw fa-commenting"></i>留言</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/blog/404/" rel="section"><i class="fa fa-fw fa-heartbeat"></i>公益 404</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/GZC986707252" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://zchao666.gitee.io/blog/2020/02/26/%E5%9F%BA%E4%BA%8EXML%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91AspectJ%E5%AE%9E%E7%8E%B0AOP/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/uploads/avatar.jpg">
      <meta itemprop="name" content="小郭">
      <meta itemprop="description" content="一个还在不断学习的编程小白！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小郭的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          基于XML配置以及基于注解开发AspectJ实现AOP
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-02-26 15:54:12" itemprop="dateCreated datePublished" datetime="2020-02-26T15:54:12+08:00">2020-02-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-03-06 02:20:15" itemprop="dateModified" datetime="2020-03-06T02:20:15+08:00">2020-03-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Spring%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index"><span itemprop="name">Spring学习</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/blog/2020/02/26/%E5%9F%BA%E4%BA%8EXML%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91AspectJ%E5%AE%9E%E7%8E%B0AOP/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/blog/2020/02/26/%E5%9F%BA%E4%BA%8EXML%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91AspectJ%E5%AE%9E%E7%8E%B0AOP/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>AspectJ是基于java语言实现的AOP框架。使用AspectJ实现Spring AOP有两种方式：基于XML配置开发AspectJ和基于注解开发AspectJ。</p>
<h3 id="基于XML配置开发AspectJ"><a href="#基于XML配置开发AspectJ" class="headerlink" title="基于XML配置开发AspectJ"></a>基于XML配置开发AspectJ</h3><p>基于XML配置是指 通过XML配置文件定义切面、切入点及通知，所有的定义必须在&lt; aop:config&gt;元素内完成。</p>
<a id="more"></a>
<table>
<thead>
<tr>
<th>元素名称</th>
<th>用途</th>
</tr>
</thead>
<tbody><tr>
<td>&lt; aop:config&gt;</td>
<td>开发AspectJ的顶层配置元素，在配置文件的&lt; beans&gt;可以包含多个该元素</td>
</tr>
<tr>
<td>&lt; aop:aspect&gt;</td>
<td>配置一个切面，是&lt; aop:config&gt;的子元素，属性ref指定定义切面的bean</td>
</tr>
<tr>
<td>&lt; aop:pointcut&gt;</td>
<td>配置切入点，&lt; aop:aspect&gt;的子元素，属性expression指定通知增强的哪些方法</td>
</tr>
<tr>
<td>&lt; aop:before&gt;</td>
<td>配置前置通知，&lt; aop:aspect&gt;的子元素 ，实现method指定前置通知方法，属性pointcut-ref指定关联的切入点</td>
</tr>
<tr>
<td>&lt; aop:after-returning&gt;</td>
<td>配置后置返回通知，&lt; aop:aspect&gt;的子元素 ，实现method指定后置返回通知方法，属性pointcut-ref指定关联的切入点，目标方法成功执行后执行</td>
</tr>
<tr>
<td>&lt; aop:around&gt;</td>
<td>配置环绕通知，&lt; aop:aspect&gt;的子元素 ，实现method指定环绕通知方法，属性pointcut-ref指定关联的切入点</td>
</tr>
<tr>
<td>&lt; aop:after-throwing&gt;</td>
<td>配置异常通知，&lt; aop:aspect&gt;的子元素 ，实现method指定异常通知方法，属性pointcut-ref指定关联的切入点 ，没有异常时不会执行</td>
</tr>
<tr>
<td>&lt; aop:after&gt;</td>
<td>配置最终通知，&lt; aop:aspect&gt;的子元素 ，实现method指定最终通知方法，属性pointcut-ref指定关联的切入点，不管是否发生异常都要执行</td>
</tr>
</tbody></table>
<p><strong>在使用AspectJ实现Spring AOP时，需要用到的jar包有：</strong></p>
<ol>
<li>spring-aop.jar</li>
<li>spring-aspects.jar</li>
<li><a href="https://mvnrepository.com/artifact/org.aspectj/aspectjweaver/1.9.5" target="_blank" rel="noopener">aspectjweaver.jar</a></li>
</ol>
<p><strong>编写切面类 ：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> gzc.aspectj.xml;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.JoinPoint;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.ProceedingJoinPoint;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 切面类 ，在此类中编写各种类型通知</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyAspectJ</span> </span>&#123;</span><br><span class="line">	<span class="comment">// 前置通知，使用JoinPoint接口作为参数获得目标对象</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">before</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.print(<span class="string">"前置通知：模拟权限控制"</span>);</span><br><span class="line">		System.out.println(<span class="string">",目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// 后置返回通知 , 目标方法成功执行后才执行</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">afterReturning</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.print(<span class="string">"后置返回通知：模拟缓存清理"</span>);</span><br><span class="line">		System.out.println(<span class="string">",目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * 环绕通知 ProceedingJoinPoint 是JoinPoint的子接口，代表可以执行的目标方法 返回值类型必须是Object</span></span><br><span class="line"><span class="comment">	 * 必须一个参数是ProceedingJoinPoint类型 必须throws Throwable</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Object <span class="title">around</span><span class="params">(ProceedingJoinPoint pjp)</span> <span class="keyword">throws</span> Throwable </span>&#123;</span><br><span class="line">		Object obj = <span class="keyword">null</span>;</span><br><span class="line">		System.out.println(<span class="string">"环绕开始，执行目标方法前，模拟开启事务"</span>);</span><br><span class="line">		<span class="comment">// 执行目标方法</span></span><br><span class="line">		obj = pjp.proceed();</span><br><span class="line">		<span class="comment">// 结束</span></span><br><span class="line">		System.out.println(<span class="string">"环绕结束，执行目标方法后前，模拟关闭事务"</span>);</span><br><span class="line">		<span class="keyword">return</span> obj;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// 异常通知</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">except</span><span class="params">(JoinPoint jp, Throwable e)</span> </span>&#123;</span><br><span class="line">		System.out.println(<span class="string">"异常通知：执行程序异常"</span> + e.getMessage());</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// 后置（最终）通知，不管目标方法是否成功都要执行</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">after</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.println(<span class="string">"后置(最终)通知，目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>配置：</strong></p>
<ol>
<li>配置相关类的Bean（包括目标对象的实现类和切面类）</li>
<li>配置切面 ：&lt; aop:aspect&gt;的ref 指向切面类的Bean</li>
<li>配置好切入点  &lt; aop:pointcut expression=” “ id=”” &gt;</li>
<li>将通知与切入点关联</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 基于XML配置 开发AspectJ --&gt;</span><br><span class="line">&lt;bean id&#x3D;&quot;myTestDao&quot; class&#x3D;&quot;gzc.dao.impl.TestDaoImpl&quot;&#x2F;&gt;</span><br><span class="line">&lt;!-- 配置切面类的bean --&gt;</span><br><span class="line">&lt;bean id&#x3D;&quot;myAspectJ&quot; class&#x3D;&quot;gzc.aspectj.xml.MyAspectJ&quot;&#x2F;&gt;</span><br><span class="line">&lt;!-- AOP配置 --&gt;</span><br><span class="line">&lt;aop:config&gt;</span><br><span class="line">	 &lt;!-- 配置切面 --&gt;</span><br><span class="line">	 &lt;aop:aspect ref&#x3D;&quot;myAspectJ&quot;&gt;</span><br><span class="line">	 	&lt;!-- 配置切入点，通知在哪些方法进行增强 </span><br><span class="line">	 		在gzc.dao包下的所有类方法以及其子包的所有类的方法</span><br><span class="line">	 	--&gt;</span><br><span class="line">	 	&lt;aop:pointcut expression&#x3D;&quot;execution(* gzc.dao..*.*(..))&quot; id&#x3D;&quot;myPointcut&quot;&#x2F;&gt;</span><br><span class="line">	 	&lt;!-- 关联前置通知 --&gt;</span><br><span class="line">	 	&lt;aop:before method&#x3D;&quot;before&quot; pointcut-ref&#x3D;&quot;myPointcut&quot;&#x2F;&gt;</span><br><span class="line">	 	&lt;!-- 关联后置返回通知 目标方法成功执行后才执行--&gt;</span><br><span class="line">	 	&lt;aop:after-returning method&#x3D;&quot;afterReturning&quot; pointcut-ref&#x3D;&quot;myPointcut&quot; &#x2F;&gt;</span><br><span class="line">	 	&lt;!-- 关联环绕通知 --&gt;</span><br><span class="line">	 	&lt;aop:around method&#x3D;&quot;around&quot; pointcut-ref&#x3D;&quot;myPointcut&quot;&#x2F;&gt;</span><br><span class="line">	 	&lt;!-- 关联异常通知 只有目标方法出现异常时才执行 , throwing设置通知的第二个参数名称--&gt;</span><br><span class="line">	 	&lt;aop:after-throwing method&#x3D;&quot;except&quot; pointcut-ref&#x3D;&quot;myPointcut&quot; throwing&#x3D;&quot;e&quot;&#x2F;&gt;</span><br><span class="line">	 	&lt;!-- 关联最终通知 不管目标方法是否成功都要执行--&gt;</span><br><span class="line">	 	&lt;aop:after method&#x3D;&quot;after&quot; pointcut-ref&#x3D;&quot;myPointcut&quot; &#x2F;&gt;</span><br><span class="line">	&lt;&#x2F;aop:aspect&gt;</span><br><span class="line">&lt;&#x2F;aop:config&gt;</span><br></pre></td></tr></table></figure>
<p><strong>expression常见示例：</strong><br><img src="https://img-blog.csdnimg.cn/20200226131204671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70" alt="expression常见示例"></p>
<h3 id="基于注解开发AspectJ"><a href="#基于注解开发AspectJ" class="headerlink" title="基于注解开发AspectJ"></a>基于注解开发AspectJ</h3><p>相比于XML 配置方式，注解的方式开发AspectJ更为便捷。</p>
<p><strong>AspectJ注解 ：</strong></p>
<table>
<thead>
<tr>
<th>注解名称</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>@Aspect</td>
<td>定义一个切面，注解在切面类上</td>
</tr>
<tr>
<td>@Pointcut</td>
<td>用于定义一个切入点表达式，在使用时需要定义一个切入点方法，该方法是一个返回值为void且方法体为空的普通方法</td>
</tr>
<tr>
<td>@Before</td>
<td>定义前置通知，通常为其指定value 属性值，该值可以是一个已有切入点，也可以直接定义切入点的expression表达式</td>
</tr>
<tr>
<td>@AfterReturning</td>
<td>定义后置返回通知，通常为其指定value 属性值，该值可以是一个已有切入点，也可以直接定义切入点的expression表达式</td>
</tr>
<tr>
<td>@Around</td>
<td>定义环绕通知，通常为其指定value 属性值，该值可以是一个已有切入点，也可以直接定义切入点的expression表达式</td>
</tr>
<tr>
<td>@AfterThrowing</td>
<td>定义异常通知，通常为其指定value 属性值，该值可以是一个已有切入点，也可以直接定义切入点的expression表达式 ；另外，还有一个throwing属性用于访问目标方法抛出的异常，该属性值与异常通知方法的参数名称一致</td>
</tr>
<tr>
<td>@After</td>
<td>定义最终通知，通常为其指定value 属性值，该值可以是一个已有切入点，也可以直接定义切入点的expression表达式</td>
</tr>
</tbody></table>
<p><strong>切面类：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> gzc.aspectj.annotation;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.JoinPoint;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.ProceedingJoinPoint;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.After;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.AfterReturning;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.AfterThrowing;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.Around;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.Aspect;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.Before;</span><br><span class="line"><span class="keyword">import</span> org.aspectj.lang.annotation.Pointcut;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*	@Aspect : 对应&lt;aop:aspect ref="aspectJByAnnotation"&gt;</span></span><br><span class="line"><span class="comment"> *	@Component : &lt;bean id="aspectJByAnnotation" class="gzc.aspectj.annotation.AspectJByAnnotation"/&gt;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Aspect</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AspectJByAnnotation</span> </span>&#123;</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * 定义切入点 如果不以这种方式定义切入点，则需要在每个通知的注解传入expression表达式作为参数</span></span><br><span class="line"><span class="comment">	 * 例如 @Before("execution(* gzc.dao..*.*(..))")</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="meta">@Pointcut</span>(<span class="string">"execution(* gzc.dao..*.*(..))"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">myPointcut</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="comment">// 相当于 &lt;aop:pointcut expression="execution(* gzc.dao..*.*(..))"</span></span><br><span class="line">		<span class="comment">// id="myPointcut"/&gt;</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 前置通知，使用JoinPoint接口作为参数获得目标对象</span></span><br><span class="line">	<span class="meta">@Before</span>(<span class="string">"myPointcut()"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">before</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.print(<span class="string">"前置通知：模拟权限控制"</span>);</span><br><span class="line">		System.out.println(<span class="string">",目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@AfterReturning</span>(<span class="string">"myPointcut"</span>)</span><br><span class="line">	<span class="comment">// 后置返回通知 , 目标方法成功执行后才执行</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">afterReturning</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.print(<span class="string">"后置返回通知：模拟缓存清理"</span>);</span><br><span class="line">		System.out.println(<span class="string">",目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * 环绕通知 ProceedingJoinPoint 是JoinPoint的子接口，代表可以执行的目标方法 返回值类型必须是Object</span></span><br><span class="line"><span class="comment">	 * 必须一个参数是ProceedingJoinPoint类型 必须throws Throwable</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="meta">@Around</span>(<span class="string">"myPointcut()"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> Object <span class="title">around</span><span class="params">(ProceedingJoinPoint pjp)</span> <span class="keyword">throws</span> Throwable </span>&#123;</span><br><span class="line">		Object obj = <span class="keyword">null</span>;</span><br><span class="line">		System.out.println(<span class="string">"环绕开始，执行目标方法前，模拟开启事务"</span>);</span><br><span class="line">		<span class="comment">// 执行目标方法</span></span><br><span class="line">		obj = pjp.proceed();</span><br><span class="line">		<span class="comment">// 结束</span></span><br><span class="line">		System.out.println(<span class="string">"环绕结束，执行目标方法后前，模拟关闭事务"</span>);</span><br><span class="line">		<span class="keyword">return</span> obj;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">// 异常通知</span></span><br><span class="line">	<span class="meta">@AfterThrowing</span>(value = <span class="string">"myPointcut()"</span>, throwing = <span class="string">"e"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">except</span><span class="params">(JoinPoint jp, Throwable e)</span> </span>&#123;</span><br><span class="line">		System.out.println(<span class="string">"异常通知：执行程序异常"</span> + e.getMessage());</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">// 后置（最终）通知，不管目标方法是否成功都要执行</span></span><br><span class="line">	<span class="meta">@After</span>(<span class="string">"myPointcut()"</span>)</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">after</span><span class="params">(JoinPoint jp)</span> </span>&#123;</span><br><span class="line">		System.out.println(<span class="string">"后置(最终)通知，目标对象："</span> + jp.getTarget() + <span class="string">",被增强的方法："</span> + jp.getSignature().getName());</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>配置：</strong></p>
<p>由于Bean都采用注解方式加入到Spring 容器中，所以配置文件只需要配置相应的注解扫描器即可；<br>采用AspectJ注解方式的话，必须要开启基于注解的AspectJ支持<br>即：<code>&lt;aop:aspectj-autoproxy/&gt;</code> </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 以注解的方式实现AspectJ --&gt;</span><br><span class="line">&lt;!-- 配置注解扫描器 --&gt;</span><br><span class="line">&lt;context:component-scan base-package&#x3D;&quot;gzc.aspectj.xml&quot;&#x2F;&gt;</span><br><span class="line">&lt;context:component-scan base-package&#x3D;&quot;gzc.dao.impl&quot;&#x2F;&gt;</span><br><span class="line">&lt;!-- 开启基于注解的AspectJ支持--&gt;</span><br><span class="line">&lt;aop:aspectj-autoproxy&#x2F;&gt;</span><br></pre></td></tr></table></figure>
<p><strong>各类通知执行过程 ：</strong><br><img src="https://img-blog.csdnimg.cn/20200226135903941.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>

    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/blog/uploads/wechatpay.jpg" alt="小郭 微信支付">
        <p>微信支付</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/blog/tags/Spring/" rel="tag"><i class="fa fa-tag"></i> Spring</a>
              <a href="/blog/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/blog/tags/AOP/" rel="tag"><i class="fa fa-tag"></i> AOP</a>
              <a href="/blog/tags/AspectJ/" rel="tag"><i class="fa fa-tag"></i> AspectJ</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2020/02/25/AOP%E9%80%9A%E7%9F%A5%E7%B1%BB%E5%9E%8B%E4%BB%A5%E5%8F%8A%E5%9F%BA%E4%BA%8E%E4%BB%A3%E7%90%86%E7%B1%BB%E7%9A%84AOP%E5%AE%9E%E7%8E%B0/" rel="prev" title="AOP通知类型以及基于代理类的AOP实现">
      <i class="fa fa-chevron-left"></i> AOP通知类型以及基于代理类的AOP实现
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2020/02/26/Spring%20%E5%A3%B0%E6%98%8E%E5%BC%8F%E4%BA%8B%E5%8A%A1%E7%AE%A1%E7%90%86%20%E4%BB%A5%E5%8F%8A%20%E4%BA%8B%E5%8A%A1%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E6%8D%95%E8%8E%B7/" rel="next" title="Spring声明式事务管理以及事务中的异常捕获">
      Spring声明式事务管理以及事务中的异常捕获 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#基于XML配置开发AspectJ"><span class="nav-text">基于XML配置开发AspectJ</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#基于注解开发AspectJ"><span class="nav-text">基于注解开发AspectJ</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="小郭"
      src="/blog/uploads/avatar.jpg">
  <p class="site-author-name" itemprop="name">小郭</p>
  <div class="site-description" itemprop="description">一个还在不断学习的编程小白！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">26</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">44</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/GZC986707252" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;GZC986707252" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/3278894871" title="微博 → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;3278894871" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>微博</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/qq_41193133" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_41193133" rel="noopener" target="_blank"><i class="fa fa-fw fa-globe"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:986707252@qq.com" title="E-Mail → mailto:986707252@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小郭</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.2
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>


  <script defer src="/blog/lib/three/three.min.js"></script>
    <script defer src="/blog/lib/three/canvas_lines.min.js"></script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/blog/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = '昵称,邮箱,链接';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'dQIv9pCVNauk7ezmEU35I8sW-gzGzoHsz',
      appKey     : '2BGfzddNSeijXJJtTofkbuJx',
      placeholder: "走过路过，千万不要错过，一起聊聊吧！",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>